package time;

public class Heure {
	private int h=0;
	private int m=0;
	private int s=0;
	private int format=24;
	private boolean am=true;
	private boolean pm=false;
	
	
	public Heure(int h, int m, int s) {
		this.h=h;
		this.m=m;
		this.s=s;
		majAmPm();
	}
	
	public Heure(int h, int m) {
		this.h=h;
		this.m=m;
		majAmPm();
	}
	
	public Heure(int h) {
		this.h=h;
		majAmPm();
	}
	
	public Heure() {
	}
	
	public void majAmPm() {
		if(format == 12) {
			if(h>12) {
				h=(h%12);
				pm=true;
				am=false;
			}
		}
	}
	
	public void switchAmPm() {
		if(pm) {
			pm=false;
			am=true;
		} else {
			pm=true;
			am=false;
		}
	}
	
	public void addHeure(int heure) {
		h+=heure;
		if(format == 12 && h>12) switchAmPm();
		h=(h%format);
			
	}
	
	public void addMinute(int minute) {
		m+=minute;
		if(m>59) addHeure(m/60);
		m=m%60;	
	}
	
	public void addSeconde(int seconde) {
		s+=seconde;
		if(s>59) addMinute(s/60);
		s=s%60;	
	}
	
	public void addDuree(Heure h) {
		addSeconde(h.getS());
		addMinute(h.getM());
		addHeure(h.getH());
	}
	
	public String toString() {
		String res;
		res=String.valueOf(h)+":"+String.valueOf(m)+":"+String.valueOf(s);
		if(format == 12 ) {
			if(am) res+=" AM";
			else res+=" PM";
		}
		return res;
	}
	
	
	
	public int getH() {
		return h;
	}

	public void setH(int h) {
		this.h = h;
	}

	public int getM() {
		return m;
	}

	public void setM(int m) {
		this.m = m;
	}

	public int getS() {
		return s;
	}

	public void setS(int s) {
		this.s = s;
	}

	public int getFormat() {
		return format;
	}

	public void setFormat(int format) {
		this.format = format;
	}

	public boolean isAm() {
		return am;
	}

	public void setAm(boolean am) {
		this.am = am;
	}

	public boolean isPm() {
		return pm;
	}

	public void setPm(boolean pm) {
		this.pm = pm;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Heure h = new Heure(18, 15, 0);
		System.out.println(h);
		h.addHeure(5);
		System.out.println(h);
		h.addHeure(5);
		System.out.println(h);
		h.addMinute(40);
		System.out.println(h);
		h.addMinute(40);
		System.out.println(h);
	}

}
